﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;

namespace ASPItalia.ModelVirtualCasting.WPF.Views
{
    /// <summary>
    /// Interaction logic for ImageEditorView.xaml
    /// </summary>
    public partial class MoviePlayerView : Window
    {
        public MoviePlayerView()
        {
            InitializeComponent();
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void imageContainer_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
        {
            e.Mode = ManipulationModes.All;
        }

        private void imageContainer_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            var element = e.Source as FrameworkElement;
            if (element != null)
            {
                MatrixTransform matrixTransform = element.RenderTransform as MatrixTransform;
                if (matrixTransform == null)
                    element.RenderTransform = matrixTransform = new MatrixTransform();

                Matrix matrix = matrixTransform.Matrix;

                ManipulationDelta deltaManipulation = e.DeltaManipulation;
                // Find the old center; arguaby this could be cached 
                Point center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
                // Change previous transform basing on new size
                center = matrix.Transform(center);
                // Zoom 
                matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y);
                // Rotation 
                matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y);
                //Translation (pan) 
                matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);

                matrixTransform.Matrix = matrix;

                e.Handled = true;

                Debug.WriteLine("Matrix: " + matrix.ToString());
            }
        }
    }
}
